<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>全员工薪资管理</title>
<link rel="stylesheet" href="../public/layui/css/layui.css" media="all">

<script src="../public/layui/layui.js" charset="utf-8"></script>
</head>
<body>
<%if(session.getAttribute("user")==null){ %>
    <script>
		window.top.location.replace("../login.jsp");
	</script>
<%}%>
<div>
	<fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
		<legend><h2>全员工薪资发放</h2></legend>
	</fieldset>
	<table class="layui-hide" id="demo" lay-filter="form"></table>
	
	<!-- 头部工具栏 -->
	<script type="text/html" id="search">
			模糊搜索：
		<div class="layui-inline">
	  	  <select id="condition" name="condition">
        	<option value=""></option>
			<option value="deptname">按部门</option>
        	<option value="rolename">按职位</option>
			<option value="userid">按员工编号</option>
		  </select>
	 	 </div>
  		<div class="layui-inline">
    		<input class="layui-input" id="conditionValue" name="conditionValue" autocomplete="off">
  		</div>
  			<button class="layui-btn" name="search" data-type="reload"  lay-event="search">搜索</button>
	</script>
<!-- 	职工状态 -->
	<script type="text/html" id="statusTpl">
		{{#  if(d.status == 0){ }}
   	 			<span style="color:#FF5722;">停职</span>
  		{{#  } else { }}
    	        <span style="color:#5FB878;">在职</span>
  		{{#  } }}
	</script>
<!-- 	薪资状态 -->
	<script type="text/html" id="salaryStatus">
		{{#  if(d.ispay == "0"){ }}
				<button class="layui-btn layui-btn-normal layui-btn-xs" lay-event="grant">发放他/她的薪资</button>
  		{{#  } else { }}
   	 			<div style="color:#009688; ">已发放</div>
  		{{#  } }}
	</script>
<!-- 	是否市场部 -->
	<script type="text/html" id="isShichang">
		
  		{{#  if(d.deptid == shichangbuId){ }}
				{{ d.commission}}
  		{{#  } else { }}
   	 			<div style="color:#FFB800; ">非市场部员工，不可有</div>
				
  		{{#  } }}
	</script>
	<script type="text/javascript">
	var shichangbuId = 50;
	layui.use(['table', 'jquery','form'],function(){
		$ = layui.jquery;
		var table = layui.table;
		var form = layui.form;
		
		var tableIns = table.render({
			elem: '#demo'
		    ,url: '../HumanServlet?button=3' //数据接口
		    ,toolbar: '#search'
		    ,page: true //开启分页
		    ,defaultToolbar:["print"]
		    ,cols: [[ //表头
		      {field: 'userid', title: '员工编号', width:120, sort: true,fixed:'left'}
		      ,{field: 'name', title: '员工姓名', width:200} 
		      ,{field: 'status', title: '员工状态', width:120, sort: true ,templet:'#statusTpl'}
		      ,{field: 'deptname', title: '所属部门', width:100}
		      ,{field: 'rolename', title: '职位', width: 180}
		      ,{field: 'basewages', title: '基本薪资<span style="color:#5FB878">(可改)</span>', width:150, sort: true}
		      ,{field: 'overtimestandard', title: '加班薪资标准<span style="color:#5FB878">(可改)</span>', width:180, sort: true} 
		      ,{field: 'leavestandard', title: '请假扣薪标准<span style="color:#5FB878">(可改)</span>', width:180, sort: true} 
		      ,{field: 'absentstandard', title: '旷工扣薪标准<span style="color:#5FB878">(可改)</span>)', width:180, sort: true} 
		      ,{field: 'totalwages', title: '总薪资', width:200, sort: true}
		      ,{field: 'meritwages', title: '加成薪资', width:200, sort: true}
		      ,{field: 'punishingwages', title: '扣除薪资', width:200, sort: true}
		      ,{field: 'commission', title: '（市场部人员特有）销售提成', width:200, sort: true,templet:'#isShichang'}
		      ,{field: 'overtime', title: '普通加班时长（单位小时）', width:200, sort: true} 
		      ,{field: 'weekovertime', title: '周末加班时长（单位小时）', width: 200, sort: true}
		      ,{field: 'festovertime', title: '节假日加班时长（单位小时）', width: 220, sort: true}
		      ,{field: 'festivalwages', title: '节日福利', width:200, sort: true}
		      ,{field: 'yearendwages', title: '年终奖', width:200, sort: true} 
		      ,{field: 'leavecount', title: '请假次数', width:200, sort: true}
		      ,{field: 'absentcount', title: '旷工次数', width:200, sort: true}
		      ,{field: 'ispay', title: '薪资发放状态', width:130, sort: true ,templet:'#salaryStatus',fixed: 'right'}
		    ]]
		});
		
		 // 顶部工具栏事件 进行搜索
		table.on('toolbar(form)', function(obj){
// 			var checkStatus = table.checkStatus(obj.config.id);
			var data = obj.data;
			var conditionValue = $('#conditionValue');
			var condition = $('#condition');
		    //这里以搜索为例
			if(conditionValue.val().length != 0){
	    		  if(condition.val() == "deptname"){
		    		  layer.msg("按部门搜索到与<span style='color:#FFB800;'>\""+conditionValue.val()+"\"</span>相关结果如下！");
		    	  }else if(condition.val() == "rolename"){
		    		  layer.msg("按职位搜索到与<span style='color:#FFB800;'>\""+conditionValue.val()+"\"</span>相关结果如下！");
		    	  }else if(condition.val() == "userid"){
		    		  layer.msg("按员工编号搜索到与<span style='color:#FFB800;'>\""+conditionValue.val()+"\"</span>相关结果如下！");
		    	  }else{
		    		  layer.msg("请先选择搜索类型！");
//		    		  layer.msg(conditionValue.val().length); //看变量数据的长度，实测有效
		    	  }
	    	  }else{
	    		  layer.msg("正在显示全部！");
	    	  }
	    	tableIns.reload({
				url: '../HumanServlet?button=3'
				,where: { //设定异步数据接口的额外参数，任意设
					"condition": condition.val(),
					"conditionValue": conditionValue.val(),
// 					"page":"1",
// 					"limit":"10"
				}
			});
		});
		table.on('tool(form)',function(obj){
			 var item = obj.data;
			 if(obj.event == "grant"){
				 $.ajax({
 					 url:"../HumanServlet?button=9&operater="+item.userid
 					 ,type:"post"
 					 ,async:false
 					 ,data: {}
 					 ,success:function(res){
 						 if(res == "true"){
 							 layer.msg("发放成功！");
 							item.ispay = 1;
 						 }else{
 							layer.msg("发放失败，因为该员工仍有申请待审核！");
 						 }
 					 }
	 				,error:function(res){
						 layer.msg(res);
					 }
 				 });
				 obj.update(item);
			 }
		}); 
	});
	</script>
</div>
</body>
</html>